﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
using The_Last_Knights.GUI;

namespace The_Last_Knights.Helper.Xml
{
    public class CheckboxReader: ReaderEntity
    {
        public override object Read(XElement element, string ID, int level)
        {                        
            Vector2[] vector2s = new Vector2[2];
            int index = 0;            
            var defs = element.Descendants(XName.Get(@"Element"));
            CheckButton button = null;
            string text;
            Label label = null;
            foreach (var xElement in defs)
            {
                string name = xElement.Attribute(XName.Get(@"ID")).Value;
                string id = XmlReader.TranslateID(name);
                string type = xElement.Attribute(XName.Get(@"Type")).Value;
                int lev = int.Parse(xElement.Attribute(XName.Get(@"Level")).Value);                
                if (lev == level + 1)
                    switch (type)
                    {
                        case "Vector2":
                            vector2s[index] = (Vector2)Factory.Read(xElement, id, type, lev);
                            index++;
                            break;
                        case "CheckButton":
                            button = (CheckButton) Factory.Read(xElement, id, type, lev);
                            break;
                        case "Label":
                            label = (Label) Factory.Read(xElement, id, type, lev);
                            //text = (string) Factory.Read(xElement, id, type, lev);
                            //label = new Text(Game, text, xElement.Attribute(XName.Get(@"Font")).Value);
                            break;
                    } 
            }
            Checkbox checkBox = new Checkbox(Game, ID, vector2s[0], vector2s[1], null, button, label);
            button.Parent = checkBox;
            return checkBox;
        }
    }
}
